package com.itheima.service.impl;

import com.itheima.Utils.DateUtils;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //reportDate
        String today = DateUtils.parseDate2String(new Date());
        //星期一
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //thisMonthNewMember
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //todayNewMember
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //totalMember
        Integer totalMember = memberDao.findMemberTotleCount();
        //thisWeekNewMember
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        //thisMonthNewMember
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);

        //todayOrderNumber
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //todayVisitsNumber(今日到诊数)
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        //thisWeekOrderNumber
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        //thisWeekVisitsNumber
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        //thisMonthOrderNumber
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        //thisMonthVisitsNumber
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

        //hotSetmeal
        //     {name:,setmeal_count:200,proportion:0.222},
        List<Map> hotSetmeal = orderDao.findHotSetMeal();


        Map<String,Object> data = new HashMap<>();
        data.put("todayNewMember",todayNewMember);
        data.put("totalMember",totalMember);
        data.put("thisWeekNewMember",thisWeekNewMember);
        data.put("thisMonthNewMember",thisMonthNewMember);
        data.put("todayOrderNumber",todayOrderNumber);
        data.put("todayVisitsNumber",todayVisitsNumber);
        data.put("thisWeekOrderNumber",thisWeekOrderNumber);
        data.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        data.put("thisMonthOrderNumber",thisMonthOrderNumber);
        data.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        data.put("hotSetmeal",hotSetmeal);
        data.put("reportDate",today);
        return data;
    }
}
